﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarbonMeter
{
    public class LicenseStateListenerClass
    {
        private LicensingManagerForm licManagerForm;
        //private MainForm frmMain;
        private LoginForm loginForm;
        //private LoadingForm formLoad;

        //her menu stripitem altindaki menuleri de içerecek sekilde bir tab 
        //classi eklemek lazim aktif olacak tablari belirlemek icin
        //private MyTabs myTabs;


        public LicenseStateListenerClass(LicensingManagerForm licManagerForm, LoginForm loginForm/*, LoadingForm formLoad, MainForm frmMain, MyTabs myTabs*/)
        {
            this.licManagerForm = licManagerForm; 
            this.loginForm = loginForm;
            //this.formLoad = formLoad;
           // this.frmMain = frmMain;
            //this.myTabs = myTabs;
        }

       //lisanslama argumanlari buraya geldiginde doldurulmus oluyor
        public void LicenseStateListener(object o, LicenseEventArg arg)
        {
           //Lisanslama Bilgisine Gore Tablari Ayarlama
           switch(arg.productName)
           {
              case "Lisans1":
                 {
                     //TODO: SetLicense fonksiyonu mainforma eklenecek
                     loginForm.SetLicense((MyTabs)TabSelections.tablo[0], arg);
                    break;
                 }
              case "Lisans2":
                 {
                     loginForm.SetLicense((MyTabs)TabSelections.tablo[1], arg);
                    break;
                 }
              case "Lisans3":
                 {
                     loginForm.SetLicense((MyTabs)TabSelections.tablo[2], arg);
                    break;
                 }
              default:
                 {
                    break;
                 }
           }

           if (arg.eventOwner.Equals("LicenseCheck"))
           {
              //formLoad.Hide();
              if (arg.licenseState.Equals("systemClock"))
              {
                 Application.Exit();
              }
              else if (arg.licenseState.Equals("trialExpire") || arg.licenseState.Equals("trialUnknown"))
              {
                 Application.Run(licManagerForm);
              }
              else if (arg.licenseState.Equals("trialDays") || arg.licenseState.Equals("trialDate") || arg.licenseState.Equals("trialCount")
                  || arg.licenseState.Equals("registered") || arg.licenseState.Equals("trialUnlimited"))
              {
                 Application.Run(loginForm);
              }
           }
           else if (arg.eventOwner.Equals("FirstComingLicenseForm")) //program baslangicindan sonra license ekrani gelmesi durumu
           {
              if(arg.licenseState.Equals("trialDays") || arg.licenseState.Equals("trialDate") || arg.licenseState.Equals("trialCount")
                 || arg.licenseState.Equals("trialUnlimited") || arg.licenseState.Equals("registered"))
              {
                 licManagerForm.Hide();
                 loginForm.Show();
              }
              else if (arg.licenseState.Equals("sameLicNumber") || arg.licenseState.Equals("trialUnknown") || arg.licenseState.Equals("wrongLicNumber")
                 || arg.licenseState.Equals("invalidLicNumber"))
              {
                 //Lisans yukleme ekrani duruyor!
              }
              else if (arg.licenseState.Equals("systemClock"))
              {
                 Application.Exit();
              }
           }
           else if (arg.eventOwner.Equals("ChildLicenseForm")) //ana formdan gonderilen lisans formu
           {

           }
        }
    }
}
